package com.bdqn.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdqn.entity.Module;
import com.bdqn.mapper.ModuleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/sys/module")
public class ModuleController {
	

	@Autowired
	private ModuleMapper moduleMapper;
	
	@RequestMapping("/findAllModule")
	public String findAllModule(HttpSession session,@RequestParam(value = "pageno", defaultValue = "1") int pageNo) {
		PageHelper.startPage(pageNo, 5);
		List<Module> listRole =moduleMapper.getAllModule();
		PageInfo<Module> pageInfo = new PageInfo<>(listRole);
		session.setAttribute("pageInfo", pageInfo);
		return "redirect:/jsp/sys/module/moduleList.jsp";
		
	
	}
	
	// 查询详情
		@RequestMapping("/moduleView")
		public String findDetails(Integer mid, Model model) {
			Module module = moduleMapper.findMoudleById(mid.longValue());
			model.addAttribute("module", module);
			return "jsp/sys/module/moduleView";
		}

		// 添加操作
		@RequestMapping("/addModule")
		public String addModule(Module module) {
			moduleMapper.addMoudle(module);
			return "redirect:/sys/module/findAllModule";// 重新跳转到控制器
		}

		// 跳转到修改页面
		@RequestMapping("/gomodify")
		public String goUpdateView(Integer mid, Model model) {
			Module module = moduleMapper.findMoudleById(mid.longValue());
			model.addAttribute("module", module);
			return "jsp/sys/module/moduleModify";
		}

		// 跳转到修改页面
		@RequestMapping("/domodify")
		public String doUpdateModule(Module module) {
			moduleMapper.updateMoudle(module);
			return "redirect:/sys/module/findAllModule";// 重新跳转到控制器
		}

		@RequestMapping("/delmodule")
		@ResponseBody
		public String delRole(int uid) {
			boolean flag = moduleMapper.dellMoudle(uid);
			if (flag) {
				return "true";
			} else {
				return "false";
			}
}
}